﻿using System;
using System.Web.UI.WebControls;
using ISHotelApp.Database;

namespace ISHotel_ASP.presentation
{
    public partial class PobytForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonVlozPobyt_Click(object sender, EventArgs e)
        {
            Pobyt newPobyt = new Pobyt();
            newPobyt.id_taxy = Convert.ToInt32(DropDownListTax.SelectedValue);
            newPobyt.prijezd = Convert.ToDateTime(TextBoxPrijezd.Text);
            newPobyt.odjezd = Convert.ToDateTime(TextBoxOdjezd.Text);
            newPobyt.id_pokoje = Convert.ToInt32(DropDownListPokoj.SelectedValue);
            newPobyt.rodne_cislo = DropDownListHost.SelectedValue;
            newPobyt.id_stravovani = Convert.ToInt32(DropDownListStravovani.SelectedValue);

            PobytTable addSourceRecord = new PobytTable();
            

            try
            {
                addSourceRecord.Insert(newPobyt);
                Response.Redirect(Request.RawUrl);
            }
            catch (Exception ex)
            {

                if (ex.Message.ToString().IndexOf("ORA-01422") >= 0) { LabelErr.Text = "Pokoj je v daném datu již obsazen"; }
                else { LabelErr.Text = ex.Message.ToString(); };
            }
            
        }

        public void button_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "DeletePobyt")
            {
                PobytTable delSourceRecord = new PobytTable();
                delSourceRecord.Delete(Convert.ToInt32(e.CommandArgument));

                if (LabelErr.Text == "")
                {
                    Response.Redirect(Request.RawUrl);
                }
            }
            if (e.CommandName == "DetailPobyt")
            {
                
            }
        }

        protected void PobytDetail_OnUpdated(object sender, ObjectDataSourceStatusEventArgs e)
        {
            GridViewPobyt.DataBind();
            PobytDetailsView.DataBind();
        }
    }
}